#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility
from extension.test_logic.RequestBase import RequestBase


class REDFISH_MAINBOARD_FRU_001(Case):
    """
        Name:
            REDFISH_MAINBOARD_FRU_001
        Label:
            主板FRU信息
        PreCondition:
            BMC web service normal
        TestStep:
            1) Get https://BMCIP/redfish/v1/Systems/1
        ExpectedResult:
            A) 返回主板FRU信息
        Parameters:

        Author:
            baixin liuya
        Last Modified:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.logger.info("Pre Test Case Start.... ")
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.bmc_host = self.device_dut.get_host(host_type=HostType.BMC)
        self.bmc_ip = self.bmc_host.local_ip
        self.bmc_user = self.bmc_host.username
        self.bmc_pwd = self.bmc_host.password

    # 测试步骤
    def procedure(self):
        self.log_step("Step1: 获取Token")
        my_request = RequestBase(self.bmc_ip, self.bmc_user, self.bmc_pwd)
        return_code, session_id = my_request.create_session()
        self.assertIsNotNone(return_code)

        self.log_step("Step2: 获取主板Fru信息")
        resp = my_request.get("/redfish/v1/Systems/1")
        self.assertIsNotNone(resp[0])
        content = resp[1]
        self.logger.info(f"接口[/redfish/v1/Systems/1]返回值：\n{content}")

        self.log_step(f"Step3: 获取主板关键信息：\nManufacturer: {content['Manufacturer']}\nSerialNumber: {content['SerialNumber']}")

        self.log_step("Step4: 清除Token")
        resp = my_request.delete_session(session_id)
        self.assertIsNotNone(resp[0])

    # 测试结束后恢复环境
    def post_test_case(self):
        pass